package com.app.brilliant.common.vo;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.List;

/**
 * 分页器类
 */
@Data
@Accessors(chain = true)
@ApiModel(value = "分页器", description = "分页器")
public class PageContainer<E> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 总记录数
     */
    @ApiModelProperty(value = "总记录数")
    private final long recordsTotal;

    /**
     * 总记录数
     */
    @ApiModelProperty(value = "总记录数")
    private final long recordsFiltered;

    /**
     * 总页数
     */
    @ApiModelProperty(value = "总页数")
    private final long totalpage;

    /**
     * 当前页数
     */
    @ApiModelProperty(value = "当前第几页")
    private final long current;

    /**
     * 数据
     */
    @ApiModelProperty(value = "数据")
    private final List<E> data;

    public PageContainer(long current, long totalnum, long totalpage, List<E> data) {
        this.recordsTotal = totalnum;
        this.recordsFiltered = totalnum;
        this.totalpage = totalpage;
        this.current = current;
        this.data = data;
    }

    public PageContainer(IPage<E> page) {
        this.recordsTotal = page.getTotal();
        this.recordsFiltered = page.getTotal();
        this.totalpage = page.getPages();
        this.current = page.getCurrent();
        this.data = page.getRecords();
    }

    public static <E> PageContainer<E> of(IPage<E> page) {
        return new PageContainer<>(page);
    }


}